package com.ruoyi.manage.task;

import com.ruoyi.common.utils.spring.SpringContextUtils;
import com.ruoyi.manage.domain.SalSalary;
import com.ruoyi.manage.service.IStaffService;
import com.ruoyi.manage.service.ISalSalaryService;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.List;

@Component("monthJob")
public class MonthJob {

    public void calculateMonthSalary() {
        // 从 Spring 容器中获取 Bean
        IStaffService staffService = SpringContextUtils.getBean(IStaffService.class);
        ISalSalaryService salaryService = SpringContextUtils.getBean(ISalSalaryService.class);

        List<Long> staffIds = staffService.getStaffIds();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
        String nowMonth = dateFormat.format(new java.util.Date());

        for (Long staffId : staffIds) {
            List<SalSalary> salaryList = salaryService.calculateSalary(staffId, nowMonth);
            System.out.println(salaryList);
        }

        System.out.println("薪资计算完成");
    }

    public void work() {
        System.out.println("monthJob.work()");
    }

    public void test() {
        System.out.println("monthJob.test()");
    }
}
